package com.kaibes.platform.article.db.entity;

import java.math.BigInteger;
import java.time.LocalDateTime;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import com.kaibes.core.base.annotation.Description;
import com.kaibes.platform.article.enums.ArticleStatus;
import com.kaibes.platform.article.enums.ArticleType;

import lombok.Data;

/**
CREATE TABLE `article` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(32) NOT NULL,
  `content` LONGTEXT,
  `user_id` INTEGER DEFAULT NULL,
  `type` ENUM('POST','PAGE') NOT NULL DEFAULT 'POST',
  `status` ENUM('PUBLISH','DRAFT','PENDING','TRASH') NOT NULL DEFAULT 'PENDING',
  `comment_count` INTEGER NOT NULL DEFAULT '0',
  `view_count` INTEGER NOT NULL DEFAULT '0',
  `category_id` TINYINT UNSIGNED DEFAULT NULL,
  `tags` VARCHAR(32) NOT NULL,
  `thumbnail` mediumtext,
  `top` BOOLEAN NOT NULL,
  `comment_able` BOOLEAN NOT NULL,
  `comment_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `category_id` (`category_id`),
  FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL,
  FOREIGN KEY (`category_id`) REFERENCES `article_category` (`id`) ON DELETE SET NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 */
@Data
@Description("文章")
public class Article {
    
    @Description("ID")
    @Min(1)
    private BigInteger id;
    @Description("标题")
    @NotBlank(message = "标题不能为空", groups = {PostMapping.class, PutMapping.class})
    private String title;
    @Description("封面")
    private String thumbnail;
    @Description("内容")
    @NotBlank(message = "内容不能为空", groups = PostMapping.class)
    private String content;
    @Description("作者")
    @Min(1)
    private Integer userId;
    @Description("分类")
    @Min(1)
    private Short categoryId;
    @Description("标签")
    private String tags;
    @Description("文章类型，如帖子、页面")
    private ArticleType type;
    @Description("文章状态，如发布、草稿、审核")
    private ArticleStatus status;
    @Description("阅读数，避免多次统计")
    private Integer viewCount;
    @Description("是否置顶")
    private Boolean top;
    @Description("评论数，避免多次统计")
    private Integer commentCount;
    @Description("是否允许评论")
    private Boolean commentAble;
    @Description("评论时间")
    private LocalDateTime commentTime;
    @Description("创建时间")
    private LocalDateTime createTime;
    @Description("更新时间")
    private LocalDateTime updateTime;
}
